﻿using System;
using System.Collections.Generic;
using UnityEngine.Events;

namespace XUtliPoolLib
{
	// Token: 0x02000193 RID: 403
	public class ObjectPool<T> : IObjectPool
	{
		// Token: 0x170000B4 RID: 180
		// (get) Token: 0x060008BC RID: 2236 RVA: 0x0002EFB9 File Offset: 0x0002D1B9
		// (set) Token: 0x060008BD RID: 2237 RVA: 0x0002EFC1 File Offset: 0x0002D1C1
		public int countAll { get; private set; }

		// Token: 0x170000B5 RID: 181
		// (get) Token: 0x060008BE RID: 2238 RVA: 0x0002EFCC File Offset: 0x0002D1CC
		public int countActive
		{
			get
			{
				return this.countAll - this.countInactive;
			}
		}

		// Token: 0x170000B6 RID: 182
		// (get) Token: 0x060008BF RID: 2239 RVA: 0x0002EFEC File Offset: 0x0002D1EC
		public int countInactive
		{
			get
			{
				return this.m_Stack.Count;
			}
		}

		// Token: 0x060008C0 RID: 2240 RVA: 0x0002F009 File Offset: 0x0002D209
		public ObjectPool(ObjectPool<T>.CreateObj creator, UnityAction<T> actionOnGet, UnityAction<T> actionOnRelease)
		{
			this.m_objCreator = creator;
			this.m_ActionOnGet = actionOnGet;
			this.m_ActionOnRelease = actionOnRelease;
			ObjectPoolCache.s_AllPool.Add(this);
		}

		// Token: 0x060008C1 RID: 2241 RVA: 0x0002F048 File Offset: 0x0002D248
		public T Get()
		{
			bool flag = this.m_Stack.Count == 0;
			T t;
			if (flag)
			{
				t = this.m_objCreator();
				int countAll = this.countAll;
				this.countAll = countAll + 1;
			}
			else
			{
				t = this.m_Stack.Pop();
			}
			bool flag2 = this.m_ActionOnGet != null;
			if (flag2)
			{
				this.m_ActionOnGet(t);
			}
			return t;
		}

		// Token: 0x060008C2 RID: 2242 RVA: 0x0002F0B8 File Offset: 0x0002D2B8
		public void Release(T element)
		{
			bool flag = element != null;
			if (flag)
			{
				bool flag2 = this.m_ActionOnRelease != null;
				if (flag2)
				{
					this.m_ActionOnRelease(element);
				}
				this.m_Stack.Push(element);
			}
		}

		// Token: 0x040003F9 RID: 1017
		private readonly Stack<T> m_Stack = new Stack<T>();

		// Token: 0x040003FA RID: 1018
		private readonly UnityAction<T> m_ActionOnGet;

		// Token: 0x040003FB RID: 1019
		private readonly UnityAction<T> m_ActionOnRelease;

		// Token: 0x040003FC RID: 1020
		private ObjectPool<T>.CreateObj m_objCreator = null;

		// Token: 0x0200038C RID: 908
		// (Invoke) Token: 0x06000F19 RID: 3865
		public delegate T CreateObj();
	}
}
